from typing import *


class Solution:
    def validPartition(self, nums: List[int]) -> bool:
        t = [True] * 3
        for i, v in enumerate(nums):
            c = False
            if i > 0 and nums[i] == nums[i - 1]:
                c = t[(i + 1) % 3]
            if (
                not c
                and i > 1
                and nums[i] == nums[i - 1]
                and nums[i] == nums[i - 2]
                or nums[i] - nums[i - 1] == 1
                and nums[i] - nums[i - 2] == 2
            ):
                c = t[i % 3]
            t[i % 3] = c
        return t[i % 3]
